<template>
	<view>
		<view class="header">
			<image :src="userInfo.avatar" mode=""></image>
			<view class="nikename">{{userInfo.nickname}}</view>
		</view>
		<view class="content">
			<van-cell title="会员中心" is-link />
			<van-cell title="我的订单" is-link />
			<van-cell title="收货地址" is-link />
			<van-cell title="我的足迹" is-link />
			<van-cell title="我的收藏" is-link />
			<van-cell title="意见反馈" is-link />
		</view>
		<view class="footer">
			<van-button type="primary" block round @click="logout">退出</van-button>
		</view>
		<van-dialog id="van-dialog" />
	</view>
</template>

<script>
	import {
		getUserInfo
	} from '../../api/user.js'
	import store from '../../store/index.js'

	export default {

		onShow() {
			if (!this.$store.state.user.token) {
				return uni.redirectTo({
					url: '/subpkg/login/login'
				})
			}
		},

		onLoad() {
			this.getUserInfoData()
		},

		data() {
			return {
				userInfo: {}
			}
		},
		methods: {
			async getUserInfoData() {
				const res = await getUserInfo()
				this.userInfo = res.data
			},
			logout() {
				this.$store.commit('user/setToken', '')
				uni.setTabBarItem({
					index: 3,
					text: '未登录'
				})
				uni.redirectTo({
					url: '/subpkg/login/login'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.header {
		height: 400rpx;
		background-color: #c82519;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		image {
			width: 250rpx;
			height: 250rpx;
			border-radius: 50%;
		}

		.nikename {
			color: white;
			font-size: 24px;
			margin-top: 10px;
		}
	}

	.footer {
		margin: 20px 20px;
	}
</style>